package com.power.project.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.project.model.P_projectuser;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;

/**
 * 参与项目人员 持久层(hibernate)
 */

public interface P_projectuserDao extends JpaRepository<P_projectuser, Serializable>, JpaSpecificationExecutor<P_projectuser>, Repository<P_projectuser, Serializable>, P_projectuserDaoCustom<P_projectuser, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from P_projectuser s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);

   List<P_projectuser> findByProjectidAndWwuseridIn(Integer projectid, List<String> wwuserid);

   @Transactional
   @Query(value = "delete from P_projectuser s where s.projectid = ?1 and wwuserid in (?2)",nativeQuery = true)
   @Modifying
   void deleteByProjectIdAndWwuserids(Integer projectId, List<String> userIds);

    List<P_projectuser> findByProjectidIn(List<Integer> pIdList);

   List<Integer> findDistinctProjectIdsByWwusernameLike(@Param("username") String username);
   @Query("SELECT DISTINCT p.projectid FROM P_projectuser p WHERE p.wwuserid IN :wwuserids")
   List<Integer> findDistinctProjectIdsByWwuseridIn(@Param("wwuserids")List<String> wwuserids);

   @Query("SELECT p.wwuserid FROM P_projectuser p WHERE p.projectid = ?1")
   List<String> findWwuseridByProjectid(Integer projectId);
}
